package com.jsjosem.aftersales.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.jsjosem.aftersales.R;
import com.jsjosem.aftersales.data.response.CustomerResponse;

import java.util.List;

public class CustomerListAdapter extends ArrayAdapter<CustomerResponse> {
    private CustomerResponse customerResponse;


    public CustomerListAdapter(@NonNull Context context, int resource, @NonNull List<CustomerResponse> objects) {
        super(context, resource, objects);
    }

    @Override
    public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {

        CustomerResponse customer = getItem(position);//得到当前项
        //为每一个子项加载设定的布局
        View view = LayoutInflater.from(getContext()).inflate(R.layout.customer_item_list, parent, false);

        TextView customerName = view.findViewById(R.id.customer_name);
        TextView customerContactNumberInfo = view.findViewById(R.id.customer_contact_number_info);
        TextView customerContactInfo = view.findViewById(R.id.customer_contact_info);
        TextView customerContactAddressInfo = view.findViewById(R.id.customer_contact_address_info);

        if (customer.getName() != null) {
            customerName.setText(customer.getName());
        }


        if (customer.getUser() != null) {
            customerContactNumberInfo.setText(customer.getUser().getPhone());
            customerContactInfo.setText(customer.getUser().getName());
        }

        customerContactAddressInfo.setText(customer.getDetail_address());

        return view;
    }
}
